<html>
<head><meta charset="utf-8"><title>How to serialize BTreeMap&lt;u64,CustomType&gt; · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20serialize.20BTreeMap.3Cu64.2CCustomType.3E.html">How to serialize BTreeMap&lt;u64,CustomType&gt;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="168303956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20serialize%20BTreeMap%3Cu64%2CCustomType%3E/near/168303956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Papp <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20serialize.20BTreeMap.3Cu64.2CCustomType.3E.html#168303956">(Jun 17 2019 at 12:04)</a>:</h4>
<p>I have a BTreeMap&lt;u64, CustomType&gt; dict as a non-public member of a struct. serde::Serialize is already derived for CustomType. The question is how do I derive Serialize for BTreeMap&lt;u64,CustomType&gt; without deriving it for the whole class?</p>



<a name="168310164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20serialize%20BTreeMap%3Cu64%2CCustomType%3E/near/168310164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20serialize.20BTreeMap.3Cu64.2CCustomType.3E.html#168310164">(Jun 17 2019 at 13:29)</a>:</h4>
<p><span class="user-mention" data-user-id="223313">@Daniel Papp</span> that doesn't really make sense. <code>Serialize</code> is implemented for <code>BTreeMap</code> by Serde itself. You can't implement a trait you don't own for a type you don't own (<a href="https://stackoverflow.com/q/25413201/155423" target="_blank" title="https://stackoverflow.com/q/25413201/155423">How do I implement a trait I don't own for a type I don't own?</a>)</p>



<a name="168310301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20serialize%20BTreeMap%3Cu64%2CCustomType%3E/near/168310301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20serialize.20BTreeMap.3Cu64.2CCustomType.3E.html#168310301">(Jun 17 2019 at 13:30)</a>:</h4>
<p>i think you need to provide more detail about your goals and what you have now</p>



<a name="168312397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20serialize%20BTreeMap%3Cu64%2CCustomType%3E/near/168312397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Papp <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20serialize.20BTreeMap.3Cu64.2CCustomType.3E.html#168312397">(Jun 17 2019 at 13:57)</a>:</h4>
<p>I see. I figured it out in the meantime. I mean that I can only define a trait implementation at the crate either where the trait or the type that I want to implement it for reside.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>